<head>
  <title>Electrolux demo</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no" />
  <link rel="manifest" href="/pwa_demo/manifest.json" />
  <link rel="stylesheet" type="text/css" href="/pwa_demo/main.css">
  <link rel="icon" href="/pwa_demo/e.png" type="image/png" />
</head>

<body>
  <script>
    //这里是进行sw.js 离线缓存的设置，注册service worker
    if (navigator.serviceWorker != null) {
      navigator.serviceWorker.register('/pwa_demo/sw.js')
        .then(function (registration) {
          console.log('Registered events at scope: ', registration.scope);
        });
    }

    // fetch('./data.json')

    // var statusEl = document.querySelector('#network-status')
    // if (!navigator.onLine) {
    //   statusEl.classList = ['is-offline']
    //   statusEl.innerText = 'Offline'
    // }

    //首先进行授权
    Notification.requestPermission().then(function (result) {
      if (result === 'granted') {
        console.log("已经授权")
      }
    });

    
    window.deferredPrompt = null;

    // 监听beforeinstallprompt事件，该事件在网站满足PWA安装条件时触发，保存安装事件
    window.addEventListener("beforeinstallprompt", e => {
        console.log("满足触发条件",e)
        e.preventDefault();
        window.deferredPrompt = e;
    });

    // 监听appinstalled事件，该事件在用户同意安装后触发，清空安装事件
    window.addEventListener("appinstalled", () => {
      window.deferredPrompt = null;
    });

    // 手动触发PWA安装
    function addToDesktop() {
      window.deferredPrompt.prompt();
    }
  </script>
  <div class="revision">测试</div>
  <img src="/pwa_demo/pwa-fonts.png">
  <div class="main-text">
    Electrolux demo 示例
  </div>
  <div class="network-message">
    Network:
    <span id="network-status" class="">Good</span>
    <button id="notifications" onclick="addToDesktop()">安装</button>
  </div>




  

  <script>

    


    
  </script>
</body>